//----------------------------------------------------------
    // 编写过程中对各个功能模块进行测试
//----------------------------------------------------------

#include "../src/logger.hpp"
#include "../src/logsink.hpp"
#include "../src/logfmt.hpp"
#include "../src/loglevel.hpp"
#include <unistd.h>
#include "../extend/rollbytimsizeSink.hpp"
#include "../src/asyncthread.hpp"
#include "../src/ymbxlog.hpp"

using namespace ymbxlog;

void GlobalBuild(){
    std::unique_ptr<ymbxlog::LoggerBuilder> global(new ymbxlog::GlobalLoggerBuild());
    global->BuildLoggername("ymbxtest4");
    global->BuildLimitLevel(ymbxlog::LogLevel::Level::INFO);
    global->BuildFormatter();
    global->BuildSink<ymbxlog::StdoutSink>();
    global->BuildSink<ymbxlog::FileSink,std::string>("./log/log.txt");
    ymbxlog::Logger::ptr logger4=global->Build();
    logger4->Debug(__LINE__,__FILE__,__FUNCTION__,1,"-this is a test debug log","(logger4)");
    logger4->Info(__LINE__,__FILE__,__FUNCTION__,2,"-this is a test Info log","(logger4)");
    logger4->Warn(__LINE__,__FILE__,__FUNCTION__,3,"-this is a test Warn log","(logger4)");
    logger4->Error(__LINE__,__FILE__,__FUNCTION__,4,"-this is a test Error log","(logger4)");
    logger4->Fatal(__LINE__,__FILE__,__FUNCTION__,5,"-this is a test Fatal log","(logger4)");
}

void test_log(const std::string& name)
{
    rinfo("测试开始");
    ymbxlog::Logger::ptr slp = ymbxlog::GetLogger(name);
    if (slp.get() == nullptr)
    {
        std::cout << "不存在" << std::endl;
        // exit(0);
        return;
    }
    LOG_DEBUG(name,1,"DEBUG");
    LOG_INFO(name,2,"INFO");
    LOG_WARN(name,3, "WARNING");
    LOG_ERROR(name, 4,"ERROR");
    LOG_FATAL(name,5,"FATAL");
    // slp->debug( 1,"DEBUG");
    // slp->info( 2,"INFO");
    // slp->warn(3, "WARNING");
    // slp->error( 4,"ERROR");
    // slp->fatal( 5,"FATAL");
    rinfo("测试结束");
}

int main(){
    // //------------------util test--------------------
    // ymbxlog::Util::Date::Now();
    // std::cout<<ymbxlog::Util::File::GetDir("../performtest/test.cc")<<std::endl;
    // std::cout << ymbxlog::Util::File::GetDir("./Util.hpp") << std::endl;
    // ymbxlog::Util::File::CreatDir("./demo.cc");
    // ymbxlog::Util::File::CreatDir("./demo/demo2/");

    // //-----------------logfmt test-------------------
    // std::shared_ptr<ymbxlog::Formatter> pfmt(new ymbxlog::Formatter());
    // // ymbxlog::Formatter::ptr pfmt=std::make_shared<ymbxlog::Formatter>("%f:%l(%F)%T[%l][%c][%t]%T%m%T[%D{%Y-%m-%d %H:%M:%S}]%n");
    // // ymbxlog::Formatter::ptr pfmt=std::make_shared<ymbxlog::Formatter>("%f:%l(%F)%T[%l][%c][%t]%T%m%T[%D{%Y-%m-%d %H:%M:%S]%");
    // // ymbxlog::Formatter::ptr pfmt=std::make_shared<ymbxlog::Formatter>("%f:%l(%F)%T[%l][%c][%t]%T%m%T[%D{%Y-%m-%d %H:%M:%S}]%");
    // // ymbxlog::LogMes::ptr logmes=std::make_shared<ymbxlog::LogMes>(1,"ymbxlog1","test.cc","main","this is a debug log",ymbxlog::LogLevel::Level::INFO);
    // ymbxlog::LogMes logmes(1,"ymbxlog1","test.cc","main","this is a debug log",ymbxlog::LogLevel::Level::INFO);
    // pfmt->Format(std::cout,logmes);
    // std::cout<<"-----------------------"<<std::endl;
    // std::string mes=pfmt->Format(logmes);
    // std::cout<<mes<<std::endl;

    //--------------------logsink test--------------------
    // ymbxlog::LogSink::ptr lsp = std::make_shared<ymbxlog::FileSink>("./log.txt");
    // ymbxlog::LogSink::ptr lsp = std::make_shared<ymbxlog::RollByFilesizeSink>("./log/log");
    // ymbxlog::LogSink::ptr lsp = std::make_shared<ymbxlog::RollByTimeSink>("./log/test");
    // ymbxlog::LogSink::ptr lsp = ymbxlog::SinkFactory<extendlog::RollByTimeSizeSink,std::string>::create("./log/log");
    // int cnt = 0;
    // while (1)
    // {
    //     std::string str = "this is a test message," + std::to_string(cnt++)+"\n";
    //     lsp->Log(str);
    //     sleep(1);
    // }

    // --------------------Synclogger test------------------------
    // ymbxlog::Formatter::ptr fmp=std::make_shared<ymbxlog::Formatter>();
    // ymbxlog::LogSink::ptr sos=std::make_shared<ymbxlog::StdoutSink>();
    // ymbxlog::LogSink::ptr fs=std::make_shared<ymbxlog::FileSink>("./log/log.txt");
    // std::vector<ymbxlog::LogSink::ptr> sinks{sos,fs};
    // ymbxlog::Logger::ptr logger1=std::make_shared<ymbxlog::SyncLogger>("ymbxtest1",ymbxlog::LogLevel::Level::DEBUG,fmp,sinks);
    // logger1->Debug(__LINE__,__FILE__,__FUNCTION__,1,"-this is a test debug log","(logger1)");
    // logger1->Info(__LINE__,__FILE__,__FUNCTION__,2,"-this is a test Info log","(logger1)");
    // logger1->Warn(__LINE__,__FILE__,__FUNCTION__,3,"-this is a test Warn log","(logger1)");
    // logger1->Error(__LINE__,__FILE__,__FUNCTION__,4,"-this is a test Error log","(logger1)");
    // logger1->Fatal(__LINE__,__FILE__,__FUNCTION__,5,"-this is a test Fatal log","(logger1)");

    //--------------------Buffer test-------------------------
    // ymbxlog::Buffer buf;
    // std::cout<<buf.Size()<<std::endl;
    // while(1){
    //     buf.Push("***************************************************\n");
    //     std::cout<<buf.Size()<<std::endl;
    //     sleep(1);
    // }

    //-------------------Asynclogger test------------------------
    // ymbxlog::Formatter::ptr fmp=std::make_shared<ymbxlog::Formatter>();
    // ymbxlog::LogSink::ptr sos=std::make_shared<ymbxlog::StdoutSink>();
    // ymbxlog::LogSink::ptr fs=std::make_shared<ymbxlog::FileSink>("./log/log.txt");
    // std::vector<ymbxlog::LogSink::ptr> sinks{sos,fs};
    // ymbxlog::Logger::ptr logger2=std::make_shared<ymbxlog::AsyncLogger>("ymbxtest2",ymbxlog::LogLevel::Level::DEBUG,fmp,sinks);
    // logger2->Debug(__LINE__,__FILE__,__FUNCTION__,1,"-this is a test debug log","(logger2)");
    // logger2->Info(__LINE__,__FILE__,__FUNCTION__,2,"-this is a test Info log","(logger2)");
    // logger2->Warn(__LINE__,__FILE__,__FUNCTION__,3,"-this is a test Warn log","(logger2)");
    // logger2->Error(__LINE__,__FILE__,__FUNCTION__,4,"-this is a test Error log","(logger2)");
    // logger2->Fatal(__LINE__,__FILE__,__FUNCTION__,5,"-this is a test Fatal log","(logger2)");

    //---------------------LocalBuilder test-------------------------
    // ymbxlog::LoggerBuilder::ptr local=std::make_shared<ymbxlog::LocalLoggerBuild>();
    // local->BuildLoggername("ymbxtest3");
    // local->BuildLimitLevel(ymbxlog::LogLevel::Level::INFO);
    // local->BuildFormatter();
    // local->BuildSink<ymbxlog::StdoutSink>();
    // local->BuildSink<ymbxlog::FileSink,std::string>("./log/log.txt");
    // ymbxlog::Logger::ptr logger3=local->Build();
    // logger3->Debug(__LINE__,__FILE__,__FUNCTION__,1,"-this is a test debug log","(logger3)");
    // logger3->Info(__LINE__,__FILE__,__FUNCTION__,2,"-this is a test Info log","(logger3)");
    // logger3->Warn(__LINE__,__FILE__,__FUNCTION__,3,"-this is a test Warn log","(logger3)");
    // logger3->Error(__LINE__,__FILE__,__FUNCTION__,4,"-this is a test Error log","(logger3)");
    // logger3->Fatal(__LINE__,__FILE__,__FUNCTION__,5,"-this is a test Fatal log","(logger3)");

    //------------------------GlobalBuilder test------------------------------
    // GlobalBuild();
    // ymbxlog::Logger::ptr logger5=ymbxlog::LoggerManager::GetInstance().GetLogger("ymbxtest4");
    // logger5->Debug(__LINE__,__FILE__,__FUNCTION__,1,"-this is a test debug log","(logger5)");
    // logger5->Info(__LINE__,__FILE__,__FUNCTION__,2,"-this is a test Info log","(logger5)");
    // logger5->Warn(__LINE__,__FILE__,__FUNCTION__,3,"-this is a test Warn log","(logger5)");
    // logger5->Error(__LINE__,__FILE__,__FUNCTION__,4,"-this is a test Error log","(logger5)");
    // logger5->Fatal(__LINE__,__FILE__,__FUNCTION__,5,"-this is a test Fatal log","(logger5)");

    //-------------------------ymbxlog test---------------------------------------
    // GlobalBuild();
    // ymbxlog::Logger::ptr logger6=ymbxlog::GetLogger("ymbxtest4");
    // logger6->debug(1,"-this is a test debug log","(logger6)");
    // logger6->info(2,"-this is a test debug log","(logger6)");
    // logger6->warn(3,"-this is a test debug log","(logger6)");
    // logger6->error(4,"-this is a test debug log","(logger6)");
    // logger6->fatal(5,"-this is a test debug log","(logger6)");
    // rdebug(1,"-this is a test debug log","(root)");
    // rinfo(2,"-this is a test debug log","(root)");
    // rwarn(3,"-this is a test debug log","(root)");
    // rerror(4,"-this is a test debug log","(root)");
    // rfatal(5,"-this is a test debug log","(root)");

    //------------------------bridge logger test-----------------------------
    // std::cout<<"局部同步日志器>>>\n";
    // ymbxlog::CreatLogger("localsynclogger","",LogLevel::Level::INFO,LoggerFiled::LOGGER_LOCAL,LoggerType::LOGGER_SYNC,AsyncType::NO);
    // test_log("localsynclogger");

    // std::cout<<"局部异步日志器>>>\n";
    // ymbxlog::CreatLogger("localasynclogger","",LogLevel::Level::INFO,LoggerFiled::LOGGER_LOCAL,LoggerType::LOGGER_ASYNC,AsyncType::ASYNC_SAFE);
    // test_log("localasynclogger");

    // std::cout<<"全局同步日志器>>>\n";
    // ymbxlog::CreatLogger("globalsynclogger","",LogLevel::Level::INFO,LoggerFiled::LOGGER_GLOBAL,LoggerType::LOGGER_SYNC,AsyncType::NO);
    // test_log("globalsynclogger");

    // std::cout<<"全局异步日志器>>>\n";
    // ymbxlog::CreatLogger("globalasynclogger","",LogLevel::Level::INFO,LoggerFiled::LOGGER_GLOBAL,LoggerType::LOGGER_ASYNC,AsyncType::ASYNC_SAFE);
    // // ymbxlog::LogSink::ptr lsp = std::make_shared<ymbxlog::FileSink>("./log.txt");
    // // ymbxlog::LogSink::ptr lsp2 = std::make_shared<ymbxlog::RollByFilesizeSink>("./log/log");
    // // ymbxlog::LogSink::ptr lsp3 = std::make_shared<ymbxlog::RollByTimeSink>("./log/test");
    // AddSinkByname<FileSink>("globalasynclogger","./log/log.txt");
    // AddSinkByname<RollByFilesizeSink>("globalasynclogger","./log/log");
    // AddSinkByname<RollByTimeSink>("globalasynclogger","./log/test");
    // test_log("globalasynclogger");

    // //创建同步局部日志器
    // Logger::ptr  lp1=CreatSyncLocalLogger("localsynclogger",LogLevel::Level::INFO);
    // //创建同步全局日志器
    // Logger::ptr lp2=CreatSyncGlobalLogger("globalsynclogger",LogLevel::Level::INFO);
    // //创建异步线程安全全局日志器
    // Logger::ptr lp3=CreatAsyncLocalLogger("localasynclogger",LogLevel::Level::INFO);
    // //创建异步线程安全局部日志器
    // Logger::ptr lp4=CreatAsyncGLobalLogger("globalasynclogger",LogLevel::Level::INFO);
    // std::cout<<"局部同步日志器>>>\n";
    // test_log("localsynclogger");

    // std::cout<<"局部异步日志器>>>\n";
    // test_log("localasynclogger");

    // std::cout<<"全局同步日志器>>>\n";
    // test_log("globalsynclogger");

    // std::cout<<"全局异步日志器>>>\n";
    // test_log("globalasynclogger");



    return 0;
}    